package com.sofwin.ruoyi.scyffinal.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.sofwin.ruoyi.scyffinal.pojo.InspectionPlan;
import com.sofwin.ruoyi.scyffinal.pojo.ScyfRiskEvent;
import com.sofwin.ruoyi.scyffinal.pojo.ScyfRiskMeasure;
import com.sofwin.ruoyi.scyffinal.pojo.ScyfRiskUnit;
import com.sofwin.ruoyi.scyffinal.service.InspectionPlanService;
import com.sofwin.ruoyi.scyffinal.service.ScyfRiskEventService;
import com.sofwin.ruoyi.scyffinal.service.ScyfRiskMeasureService;
import com.sofwin.ruoyi.scyffinal.service.ScyfRiskUnitService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("/inspectionPlan")
public class InspectionPlanController extends BaseController {
    @Autowired
    private InspectionPlanService inspectionPlanService;
    @Autowired
    private ScyfRiskMeasureService scyfRiskMeasureService;
    @Autowired
    private ScyfRiskUnitService scyfRiskUnitService;
    @Autowired
    private ScyfRiskEventService scyfRiskEventService;
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) InspectionPlan inspectionPlan){
        startPage();
        List<InspectionPlan> list = inspectionPlanService.selectInspectionPlanList(inspectionPlan);
        return getDataTable(list);
    }

/*    @GetMapping(value = "{id}")
    public AjaxResult getInfo(@PathVariable Long id){
         inspectionPlanService.getInfoById(id);
    }*/
    //批量删除
    @DeleteMapping("{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        inspectionPlanService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }


    /**
     * 拿到风险管理模块（风险点）
     * @return
     */
    @GetMapping("/getScyfRiskUnit")
    public TableDataInfo scyfRiskUnitList(){
        List<ScyfRiskUnit> list = scyfRiskUnitService.list();
        return getDataTable(list);
    }

    /**
     * 根据id获取风险事件下拉框
     * @param riskUnitId
     * @return
     */
    @GetMapping("/getScyfRiskEvent/{riskUnitId}")
    public AjaxResult getScyfRiskEvent(@PathVariable("riskUnitId") Long riskUnitId)
    {
        LambdaQueryWrapper<ScyfRiskEvent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ScyfRiskEvent::getRiskUnitId,riskUnitId);
        List<ScyfRiskEvent> list = scyfRiskEventService.list(queryWrapper);
        return AjaxResult.success(list);
    }


    /**
     * 根据id获取管控措施
     * @param riskEventId
     * @return
     */
    @GetMapping("/getScyfRiskMeasure/{riskEventId}")
    public AjaxResult getScyfRiskMeasure(@PathVariable("riskEventId") Long riskEventId){
        LambdaQueryWrapper<ScyfRiskMeasure> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ScyfRiskMeasure::getRiskEventId,riskEventId);
        List<ScyfRiskMeasure> list = scyfRiskMeasureService.list(queryWrapper);
        return AjaxResult.success(list);
    }
}
